<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <head th:replace="common/common_css :: css(~{::link})">
    </head>
    <title>门诊收费</title>
    <link rel="stylesheet" type="text/css" th:href="@{/css/chosen.min.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{css/mcss/mcss_outpatientToll.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{css/mcss/mcss_notice.css}"/>
    <link type="text/css" rel="stylesheet" th:href="@{/css/preloader.css}">

    <link th:href="@{/xtiper/css/xtiper.css}" type="text/css" rel="stylesheet"/>
    <script th:src="@{/xtiper/js/xtiper.js}" type="text/javascript"></script>
</head>
<body>

<div id="preloader">
    <div id="preloader-inner"></div>
</div>
<div id="wrapper">
    <div th:replace="common/common_left :: left"></div>

    <div id="content-wrapper" class="d-flex flex-column content-wrapper">
        <div id="content">
            <div th:replace="common/common_head :: head"></div>

            <!--正文-->
            <div>
                <div class="card shadow mb-4" style="margin-left: 2.5%">

                    <div class="card-header py-3" style="display: flex;">
                        <h6 class="m-0 font-weight-bold text-primary">划价收费</h6>
                        <button class="btn btn-info mybutton-toll" >打印</button>
                    </div>

                    <div class="card-body toll">

                        <div class="split split-horizontal card prescription" id="myprescription">

                            <div style="display: flex">
                                <h4 style="font-family: STLiti,serif;color: #2C9FAF">SHOSPITAL</h4>

                                <h2>门诊处方笺</h2>

                                <div style="font-size: 15px;margin-left: 26%">
                                    <div id="nowDate"></div>
                                </div>

                            </div>


                            <div class="textbox" >

                                处方号<input type="text" id="prescriptionNum" style="width: 170px"
                                          readonly="readonly" >
                                科室<input type="text" id="department" style="width: 110px" readonly="readonly">&emsp;
                                日期<input type="text" id="createDate" style="width: 133px" readonly="readonly" >
                                <br> <br>
                                姓名<input type="text" id="name" style="width: 110px" readonly="readonly">&emsp;
                                性别<input type="text" id="sex" style="width: 90px" readonly="readonly">
                                民族<input type="text" id="nationality" style="width: 90px" readonly="readonly">
                                年龄<input type="text" id="age" style="width:90px" readonly="readonly">
                                <br> <br>
                                初步诊断<input type="text" id="diagnosisResult1" readonly="readonly" style="width:505px">
                            </div>

                            <div style="display: flex">
                                <div style="font-size: 1.1rem">
                                    <img style="width: 70px;height: 70px;margin-left: 60px;"
                                         th:src="@{/images/icon/prescription.png}">
                                </div>


                            </div>

                            <div>
                                <div id="prescription" class="prescription-1">

                                   <!-- <ol>

                                        <li>布洛芬缓释片<span style="margin-left:100px">0.3g*20*1盒</span></li><div style="margin: 10px 0 10px 5px;">用法：<sapn>随便</sapn><sapn style="margin-left:40px">口服</sapn><sapn style="margin-left:60px">每日两次</sapn></div><li>布洛芬缓释片<span style="margin-left:100px">0.3g*20*1盒</span></li><div style="margin: 10px 0 10px 5px;">用法：<sapn>随便</sapn><sapn style="margin-left:40px">口服</sapn><sapn style="margin-left:60px">每日两次</sapn></div></ol>
-->
                                </div>

                                <div style="margin: 0 70px 0 60px">
                                    <div style="display: flex;">
                                        <div style="display: flex;width: 430px">
                                            <div>
                                                医嘱
                                            </div>
                                            <div style="margin-left: 10px" id="medicalOrder"></div>
                                        </div>
                                        <div style="display: flex;">
                                            <div>医师</div>
                                            <div>
                                                <input type="text" id="doctorName" style="width:80px"
                                                       readonly="readonly">
                                            </div>
                                        </div>

                                    </div>
                                    <hr>
                                    <div style="display: flex;">
                                        <div style="display: flex">
                                            <div>药费</div>
                                            <div>
                                                <input type="text" id="drugCost" style="width:80px" readonly="readonly">
                                            </div>
                                        </div>
                                        <div style="display: flex;margin-left: 20px">
                                            <div>检查费</div>
                                            <div>
                                                <input type="text" id="examinationCost" style="width:80px"
                                                       readonly="readonly">
                                            </div>
                                        </div>
                                        <div style="margin-left: 170px">
                                            签字:
                                        </div>


                                    </div>
                                </div>
                            </div>

                        </div>

                        <div class="split split-horizontal tolloperation" id="tolloperation">

                            <div class="CardIdInfor">
                                卡号<input type="text" style="width: 140px;height: 32px"  id="cardId">
                                <div class="my-tooltip" >
                                    <img class="png" th:src="@{/images/icon/notice.png}" >
                                    <div class="tooltip">手动输入就诊卡号后，只需点击最右侧搜索按钮，选择收费状态便可查询。读取就诊卡需配合IC读卡器来使用！</div>
                                </div>
<!--                                <div class="mybtn1">-->
<!--                                    <button class="btn btn-info" onclick="getCardIdInfor()">读取就诊卡</button>-->
<!--                                </div>-->

                                <div style="margin-left: 50px">
                                    收费状态<select class='tollStatus' data-placeholder=' ' id="outpatient_queue_status">

                                    <option value=""></option>

                                    <option value="0">未收费</option>
                                       
                                    <option value="1">已收费</option>
                                     
                                </select>
                                </div>
                                <div class="mybtn1" >
                                    <button class="btn btn-info" onclick="buttonFind()" >
                                        <img class="png" th:src="@{/images/icon/search.png}" >
                                    </button>
                                </div>
                            </div>
                            <br>
                            <div class="toll_table">
                                <div class="bootstrap-table">
                                    <div class="fixed-table-toolbar"><div class="bs-bars float-left"></div></div>
                                    <div class="fixed-table-container fixed-height" style="height: 400px; padding-bottom: 49.7778px;">
                                <table  class="table table-bordered table-hover" style="margin-top: -49.7778px;">
                                    <thead class="">
                                    <tr><th style="text-align: center; width: 35px; " data-field="no">
                                        <div class="th-inner ">序号</div><div class="fht-cell"></div></th><th style="text-align: center; vertical-align: middle; " data-field="outpatientDate">
                                        <div class="th-inner ">门诊时间</div><div class="fht-cell"></div></th><th style="text-align: center; vertical-align: middle; " data-field="department">
                                        <div class="th-inner ">科室</div><div class="fht-cell"></div></th><th style="text-align: center; vertical-align: middle; " data-field="registerType">
                                        <div class="th-inner ">挂号类型</div><div class="fht-cell"></div></th><th style="text-align: center; vertical-align: middle; " data-field="doctorName">
                                        <div class="th-inner ">医生名称</div><div class="fht-cell"></div></th><th style="text-align: center; vertical-align: middle; " data-field="prescriptionNum">
                                        <div class="th-inner ">处方号</div><div class="fht-cell"></div></th><th style="text-align: center; " data-field="operation">
                                        <div class="th-inner ">操作</div><div class="fht-cell"></div></th></tr></thead>
                                    <tbody id="buttonApprend">
                                    <!--<tr data-index="0" >
                                        <td style="text-align: center; width: 35px; " ></td>
                                        <td style="text-align: center; vertical-align: middle; " ></td>
                                        <td style="text-align: center; vertical-align: middle; " ></td>
                                        <td style="text-align: center; vertical-align: middle; " ></td>
                                        <td style="text-align: center; vertical-align: middle; " ></td>
                                        <td style="text-align: center; vertical-align: middle; " ></td>
                                        <td style="text-align: center; ">
                                            <button id="btn_toll" class="btn btn-outline-primary">选择</button>&nbsp;&nbsp;</td></tr>-->
                                    </tbody>
                                </table>
                                <div class="fixed-table-border" style="height: 260px;"></div>
                            </div>
                            </div>
                            </div>
                            <div style="margin: 70px 0 0 100px">
                                <div style="display: flex;">
                                    <div>
                                        合计：
                                    </div>
                                    <div>
                                        <input type="text" id="total" style="width:90px" readonly="readonly">
                                    </div>
                                    <div style="margin-left: 30px">
                                        付款方式<select class='payType' id="toPayController" data-placeholder=' ' >
                                         
                                        <option value=""></option>

                                        <option value="现金">现金</option>
                                           
                                        <option value="支付宝">支付宝</option>
                                         
                                    </select>
                                    </div>
                                </div>
                            </div>

                            <div class="textbox_2" style="display: flex">
                                <div style="width: 60%">
                                    <div id="money" style="display: none">
                                        实付<input type="text" id="payMoney" style="width: 120px"
                                                 >元&emsp;&emsp;&emsp;
                                        找零<input type="text" id="Change" style="width: 100px;color: red"
                                                 readonly="readonly">元

                                    </div>

                                    <div id="apay" style="display: none;margin-left: 40%">
                                        <img style="width: 100px;height: 100px;"
                                             th:src="@{/images/icon/apay.jpg}">
                                    </div>
                                </div>
                                <div class="mybtn3">

                                    <button class="btn btn-info" onclick="submitToPay()">提交信息</button>

                                </div>
                                <form >

                                </form>

                            </div>

                        </div>

                    </div>
                </div>
            </div>

        </div>
    </div>
</div>
<div>
    <div th:replace="common/common_js :: js(~{::script})"></div>
    <script type="text/javascript" th:src="@{/js/jquery.preloader.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/chosen.jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/split.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/jquery.jqprint-0.3.js}"></script>
    <script th:src="@{/sb-admin-2/bootstrap/bootstrap-table.min.js}"></script>
    <script th:src="@{/sb-admin-2/bootstrap/bootstrap-table-zh-CN.js}"></script>
    <script type="text/javascript" th:src="@{/js/mjs/mjs_outpatientToll.js}"></script>
    <script type="text/javascript" th:src="@{/js/Print.js}"></script>
</div>


</body>

<script>

    //查询诊单
    function buttonFind() {
        var cardId = $("#cardId").val();
        var outpatientQueueStatus = $("#outpatient_queue_status").val();
        var param = {"cardId":cardId,"outpatientQueueStatus":outpatientQueueStatus};
        $.getJSON("/outpatient/buttonFind",param,function (data) {
            if(data.state==200){
                var medical = data.data;
              //  alert(medical.toString());
                $("#buttonApprend").empty();
                for(var i=0;i<=medical.length;i++) {
                    var time1 = new Date(medical[i].time).toJSON();
                    var d = new Date(time1);
                    //如果小于9，前面加0
                    var day = ("0" + d.getDate()).slice(-2);
                    //如果小于9，前面加0
                    var month = ("0" + (d.getMonth() + 1)).slice(-2);
                    //拼接日期
                    var times=d.getFullYear() + '-' + (month) + '-' + (day);
                    //时分秒拼接
                    var times1 = times+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
                    var medicalTime = times1;

                    var medicalInfo ='<tr data-index="0" >'+
                        '<td style="text-align: center; width: 35px; ">' + (i+1) + '</td>' +
                        '<td style="text-align: center; vertical-align: middle; " >' + medicalTime +  '</td>' +
                        '<td style="text-align: center; vertical-align: middle; " >' + medical[i].departmentName + '</td>' +
                        '<td style="text-align: center; vertical-align: middle; " >' + medical[i].registerType + '</td>' +
                        '<td style="text-align: center; vertical-align: middle; " >' + medical[i].doctorName + '</td>' +
                        '<td style="text-align: center; vertical-align: middle; " >' + medical[i].prescriptionNum + '</td>' +
                        '<td style="text-align: center; ">' +
                        '<button id="btn_toll" class="btn btn-outline-primary" onclick="getMedicalRecord2(this)">选择<input type="hidden" value="'+medical[i].prescriptionNum+'"/></button>&nbsp;&nbsp;'+'</td>'+
                        '</tr>';
                    /*console.log($("#buttonApprend"));*/
                $("#buttonApprend").append(medicalInfo);
            }
            }
            else if(data.state==206){
                swal(data.message,"","error");
                $("#buttonApprend").empty();
            }
            else {
                swal(data.message,"","error");
            }
        })
    };

    //得到门诊处方笺信息
     function getMedicalRecord2(a) {
        var num = $(a).children().val();
        var prescriptionNum = num;
        var cardId = $("#cardId").val();
        var param = {"cardId":cardId,"prescriptionNum":prescriptionNum};
        $.getJSON("/outpatient/findMedicalRecord",param,function (data) {
            if(data.state==200){
                $("#prescriptionNum").val(data.data.prescriptionNum);
                $("#diagnosisResult1").val(data.data.diagnosisResult);
                //时间
                var createDate = $("#createDate");
                var time = new Date(data.data.createDatetime).toJSON();
                var d = new Date(time);
                //如果小于9，前面加0
                var day = ("0" + d.getDate()).slice(-2);
                //如果小于9，前面加0
                var month = ("0" + (d.getMonth() + 1)).slice(-2);
                //拼接日期
                var times=d.getFullYear() + '-' + (month) + '-' + (day);
                //时分秒拼接
                var times1 = times+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
                //把转换的日期赋值给input
                createDate.val(times1);

                $("#department").val(data.data1.department);
                $("#name").val(data.data2.name);
                $("#sex").val(data.data2.sex);
                $("#nationality").val(data.data2.nationality);
                var age = $("#age");
                //拿到当前时间和病人的出生日期进行判断
                var dateTime=new Date();
                var birthday = new Date(data.data2.birthday).toJSON();
                var birthdayTime = new Date(birthday);
                var birthdayYear=birthdayTime.getFullYear();
                if(dateTime.getFullYear()==birthdayTime.getFullYear()){
                    age.val((birthdayTime.getMonth()+1)+"个月");
                }else if(dateTime.getFullYear()>birthdayTime.getFullYear()
                    && dateTime.getMonth()>(birthdayTime.getMonth())){
                    age.val((dateTime.getFullYear()-birthdayYear)+"岁");
                }else if(dateTime.getFullYear()>birthdayTime.getFullYear()
                    && dateTime.getMonth()<(birthdayTime.getMonth())){
                    age.val((dateTime.getFullYear()-birthdayYear-1)+"岁");
                }else if(dateTime.getFullYear()>birthdayTime.getFullYear()
                    && dateTime.getMonth()==(birthdayTime.getMonth())){
                    if(dateTime.getDate()<birthdayTime.getDate())
                        age.val((dateTime.getFullYear()-birthdayYear-1)+"岁");
                    if(dateTime.getDate()>birthdayTime.getDate())
                        age.val((dateTime.getFullYear()-birthdayYear)+"岁");
                }

                $("#prescription").html(data.data.prescription);
                $("#drugCost").val(data.data.drugCost);
                /*$("#examinationCost").val(0);*/
                /*var examinationCost = parseInt($("#examinationCost").val());*/
                $("#doctorName").val(data.data1.doctor);
                $("#medicalOrder").html(data.data.medicalOrder);
                $("#total").val(data.data.drugCost);

                /*xtip.msg(data.message, {icon: 'h'});*/
            }
            else {
                swal(data.message,"","error");
            }
        })
    };

     //现金支付改变
     $("#toPayController").change(function () {
            var toPayController = $("#toPayController").val();
            if(toPayController=="现金"){
                $("#payMoney").change(function () {
                    var payMoney = parseInt($("#payMoney").val());
                    var total = parseInt($("#total").val());
                    $("#Change").val(payMoney-total);
                    var Money = parseInt($("#Change").val());
                    if(Money<0){
                        swal("实付金额不足","","error");
                        return;
                    }
                })
            }

     });

    //验证付费信息(现金)
    function CheckToPayMoney() {
        var payMoney = $("#payMoney").val();
        //判断是否为数字
        var reg = /^[0-9]+\.?[0-9]*$/;
        if (!reg.test(payMoney)) {
            swal("填写有误","","error");
            return;
        }
        if(payMoney==""){
            swal("请填写实付金额","","error");
            return;
        }
        if($("#outpatient_queue_status").val()==1){
            swal("该诊单已付费","","error");
            return;
        }else if($("#outpatient_queue_status").val()==0){
            var prescriptionNum = $("#prescriptionNum").val();
            var param = {"prescriptionNum":prescriptionNum};
            $.post("/CheckToPay",param,function (data) {
                if(data.state==200){
                    alert(data.message);
                    MoneyToPay();
                }
                else {
                    swal(data.message,"","error");
                    return; }
            })
        }
        else{
            swal("未知错误","","error");
            return;
        }
    }

    //验证付费信息(支付宝)
    function CheckToPayAlipay() {
        if($("#outpatient_queue_status").val()==1){
            swal("该诊单已付费","","error");
            return;
        }else if($("#outpatient_queue_status").val()==0){
            var prescriptionNum = $("#prescriptionNum").val();
            var param = {"prescriptionNum":prescriptionNum};
            $.post("/CheckToPay",param,function (data) {
                if(data.state==200){
                    AlipayToPay();
                }
                else {
                    swal(data.message,"","error");
                    return; }
            })
        }
        else{
            swal("未知错误","","error");
            return;
        }
    }

    //提交信息
    function submitToPay() {
        if($("#toPayController").val()=="现金"){
            CheckToPayMoney();
        }
        else if($("#toPayController").val()=="支付宝"){
            CheckToPayAlipay();
        }
    }

    //现金支付
    function MoneyToPay() {
        var cardId = $("#cardId").val();
        var prescriptionNum = $("#prescriptionNum").val();

        var param = {"cardId":cardId ,"prescriptionNum":prescriptionNum}
        $.post("/MoneyToPay",param,function (data) {
                if(data.state==200){
                    location.reload();
                }
                else{
                    swal(data.message,"","error");
                    location.href("/404");
                }
        })
    }

    //支付宝支付
    function AlipayToPay() {
        var totalPrice = $("#total").val();
        var cardId = $("#cardId").val();
        var prescriptionNum = $("#prescriptionNum").val();
        var name = $("#name").val();
        //沙箱操作支付宝不能使用ajax
        location.href="/AlipayToPay?totalPrice="+totalPrice+"&cardId="+cardId+"&prescriptionNum="+prescriptionNum+"&name="+name;
    }
</script>
</html>

